package com.eboss.sbs.activity.base;

import android.annotation.SuppressLint;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;

import com.eboss.sbs.R;
import com.eboss.sbs.enums.TypeBottomTab;
import com.eboss.sbs.myapplication.MyApplication;
import com.nostra13.universalimageloader.core.ImageLoader;

@SuppressWarnings("deprecation")
public class MainTabActivity extends TabActivity implements OnTabChangeListener
{
	
	//public static final String BOTTOM_MENU_INDEX = "BOTTOM_MENU_INDEX";
	
	public static final String NOTIFY_CODE_TAG = "NOTIFY_CODE_TAG";
	/**刷新显示MainTabMenu*/
	public static final int NOTIFY_CODE_REFLASH = 1;
	/**刷新购物车商品数量标识*/
	public static final int NOTIFY_CODE_UPDATE_SHOPCAR = 2;
	
	private static final String BOTTOM_TAG = "bottom_menu_";
	
	TypeBottomTab[] tabs = TypeBottomTab.values();
	private TabHost mTabHost;
	private int mCurrentTabIndext = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.basic_tab);
		
		showImmersiveNotification();
		
		MyApplication.getmInstance().showImmersiveNotification(MainTabActivity.this);
		
		initView();
		
//		IntentFilter filter = new IntentFilter(MyApplication.RECEIVER_UPDATE_SHOPCARNUM_TAG); 
//        registerReceiver(broadcastReceiver, filter);
		
	}
	
	private void initView()
	{
		mTabHost = getTabHost();
		mTabHost.setOnTabChangedListener(this);
		if(mTabHost.getChildCount()!=0){mTabHost.clearAllTabs();}
		int tabnums = tabs.length;
		for (int i = 0; i < tabnums; i++) {
			RelativeLayout mLayoutTab = (RelativeLayout) getLayoutInflater().inflate(R.layout.basic_tab_view, null);
			ImageView tabIcon1 = (ImageView) mLayoutTab.findViewById(R.id.tab_img);
			tabIcon1.setBackgroundResource(tabs[i].getTabIcon());
			TextView tabTv1 = (TextView) mLayoutTab.findViewById(R.id.tab_txt);
			tabTv1.setText(tabs[i].getTabName());
			mTabHost.addTab(mTabHost.newTabSpec(BOTTOM_TAG+i).setIndicator(mLayoutTab).setContent(new Intent(MainTabActivity.this, tabs[i].getTargetClass())));
		}
		mTabHost.setCurrentTab(mCurrentTabIndext);
	}
	
	@Override
	public void onTabChanged(String arg0){}
	
//	/**更新购物车物品数量标识*/
//	BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
//		@Override
//		public void onReceive(Context context, Intent intent) {
//			int notify_code = intent.getIntExtra(NOTIFY_CODE_TAG, NOTIFY_CODE_REFLASH);
//			if(notify_code==NOTIFY_CODE_REFLASH){initView();}
//			else if(notify_code==NOTIFY_CODE_UPDATE_SHOPCAR){updateShopCarNum();}
//		}
//	};
	
//	private void updateShopCarNum(){}
	
	@Override
	protected void onNewIntent(Intent intent)
	{
		super.onNewIntent(intent);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
	}
	
	@Override
	protected void onDestroy() {
		ImageLoader.getInstance().clearMemoryCache();
		super.onDestroy();
	}
	
	/**沉浸式通知栏显示*/
	@SuppressLint("InlinedApi")
	protected void showImmersiveNotification(){
		//if(mContext==null)return;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {  
        	getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);		//透明状态栏
//            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);	//透明导航栏
        }
	}
	
}
